package com.zz.springboot.processor;

import com.zz.springboot.processor.bag.BagDataProcessor;
import com.zz.springboot.processor.multiToOne.MultiToOneProcessor;
import com.zz.springboot.processor.oneToOne.OneToOneDataProcessor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class DataProcessorFactory {

    @Autowired
    MultiToOneProcessor multiToOneProcessor;

    @Autowired
    BagDataProcessor bagDataProcessor;

    @Autowired
    OneToOneDataProcessor oneToOneDataProcessor;

    /**
     * 根据输入数据类型获取对应的处理器
     * @param data 输入数据
     * @return 对应的数据处理器
     */
    public DataProcessor getProcessor(String data) {
        if (data.contains("各") && !data.contains("包") || data.contains("(") || data.contains("（")) {
            return multiToOneProcessor;
        } else if (data.contains("包")) {
            return bagDataProcessor;
        } else {
            return oneToOneDataProcessor;
        }
    }
}
